<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Auth;
use App\Model\AdminUsers;
use App\Model\Role;
use App\Model\Permission;

class RbacRoleMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
 
        //判断是否登录,没有登录就重定向去登录页面
        if (!$request->session()->exists('admin_user')) {
             return redirect('/home/login');
        }

        //获取session的用户名
        $admin_user = $request->session()->get('admin_user');

        //下两行是用来取登录用户的ID的
        $sess = $request->session()->get('admin_user_arr');
        $id = $sess['id'];

        //登录用户的模型
        $usermod = new AdminUsers();

        $b = $usermod->haspermission($id);

        return $next($request);
    }
}
